home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’91 / ColorHack 1991 / the demo / myWDEF.c next >
Encoding:
C/C++ Source or Header  |  1990-06-15  |  5.3 KB  |  259 lines  |  [TEXT/KAHL]

  1. /*my header so I can identify my WDEF patch*/
  2. header()
  3.     {
  4.     extern pascal long main();
  5.     asm
  6.         {
  7.         lea header,a0
  8.         jmp main
  9.         dc.b "Eric's wdef"
  10.         }
  11.     }
  12.  
  13. #include "MacTypes.h"
  14. #include "MemoryMgr.h"
  15. #include "Quickdraw.h"
  16. #include "WindowMgr.h"
  17. #include "SetUpA4.h"
  18.  
  19. #define NO 0
  20. #define YES 1
  21. #define nil 0L
  22. #define origID 69             /*for installer version*/
  23. /* #define origID 0*/     /*for init version*/
  24. pascal long main();
  25. void dohitTest(WindowPtr,long);
  26.  
  27. Handle    hh = nil;
  28.  
  29. pascal long main(variation, whichWindow, message, parameter)
  30.  short variation;
  31.  WindowPtr whichWindow;
  32.  short message;
  33.  long parameter;
  34.     {
  35.     long    result;
  36.     WindowPtr    savePort;
  37.     
  38.     RememberA0();
  39.     SetUpA4();
  40.     
  41.     if ( hh == nil )
  42.         hh = GetResource('WDEF',origID);
  43.  
  44.     if ( *hh == nil )
  45.         LoadResource(hh);
  46.         
  47.     
  48.     HLock(hh);
  49.     
  50.     asm
  51.         {
  52.         clr.l        -(a7)
  53.         move        variation,-(a7)
  54.         move.l    whichWindow,-(a7)
  55.         move        message,-(a7)
  56.         move.l    parameter,-(a7)
  57.         
  58.         movea.l    hh,a0
  59.         move.l    (a0),a0
  60.         jsr            (a0)
  61.         
  62.         move.l    (a7)+,d0
  63.         move.l    d0,result
  64.         }
  65.  
  66.     HUnlock(hh);
  67.     
  68.     if ( message == wDraw )
  69.         {
  70.         if ( variation == 0 ||
  71.                  variation == 4 ||
  72.                  variation == 5 ||
  73.                  variation == 8 ||
  74.                  variation == 12 )
  75.             dowindowdraw(whichWindow,parameter);
  76.         }
  77.         
  78.     if ( message == 1 && result == wInDrag && whichWindow == FrontWindow() )
  79.         {
  80.         GetPort(&savePort);
  81.         SetPort(whichWindow);
  82.         dohitTest(whichWindow,parameter);
  83.         SetPort(savePort);
  84.         }
  85.     
  86.     RestoreA4();
  87.     
  88.     return(result);
  89.     }
  90.  
  91. void dohitTest(theWindow,param)
  92. WindowPtr    theWindow;
  93. long        param;
  94.     {
  95.     Point                hitPt;
  96.     MenuHandle    mm;
  97.     long                Result;
  98.     DateTimeRec date;
  99.     Str255            ts,os;
  100.     int                    len = 0;
  101.     int                 hour,isAM;
  102.     WindowPeek    wRec;
  103.     Rect                rr;
  104.     
  105.     hitPt.v = HiWord(param);
  106.     hitPt.h = LoWord(param);
  107.     
  108.     wRec = (WindowPeek)theWindow;
  109.     rr = (*(wRec->strucRgn))->rgnBBox;
  110.     
  111.     rr.bottom = rr.top + 15;
  112.     rr.top += 4;
  113.     rr.left = rr.right - 40;
  114.     rr.right = rr.left + 11;
  115.  
  116.     if ( PtInRect(hitPt,&rr) )
  117.         {
  118.         GetTime(&date);
  119.         
  120.         mm = NewMenu(140,"\pmenu name");
  121.         AppendMenu (mm,"\pToday is:");
  122.         if ( StringWidth("\pToday is:") > len ) len = StringWidth("\pToday is:");
  123.  
  124.         switch(date.dayOfWeek)
  125.             {
  126.             case 1:
  127.                 AppendMenu (mm,"\p  Sunday");
  128.                 if ( StringWidth("\p  Sunday") > len )
  129.                     len = StringWidth("\p  Sunday");
  130.                 break;
  131.             case 2:
  132.                 AppendMenu (mm,"\p  Monday");
  133.                 if ( StringWidth("\p  Monday") > len )
  134.                     len = StringWidth("\p  Monday");
  135.                 break;
  136.             case 3:
  137.                 AppendMenu (mm,"\p  Tuesday");
  138.                 if ( StringWidth("\p  Tuesday") > len )
  139.                     len = StringWidth("\p  Tuesday");
  140.                 break;
  141.             case 4:
  142.                 AppendMenu (mm,"\p  Wednesday");
  143.                 if ( StringWidth("\p  Wednesday") > len )
  144.                     len = StringWidth("\p  Wednesday");
  145.                 break;
  146.             case 5:
  147.                 AppendMenu (mm,"\p  Thursday");
  148.                 if ( StringWidth("\p  Thursday") > len )
  149.                     len = StringWidth("\p  Thursday");
  150.                 break;
  151.             case 6:
  152.                 AppendMenu (mm,"\p  TGI Friday");
  153.                 if ( StringWidth("\p  TGI Friday") > len )
  154.                     len = StringWidth("\p  TGI Friday");
  155.                 break;
  156.             case 7:
  157.                 AppendMenu (mm,"\p  Saturday");
  158.                 if ( StringWidth("\p  Saturday") > len )
  159.                     len = StringWidth("\p  Saturday");
  160.                 break;
  161.             default:
  162.                 AppendMenu (mm,"\p  No Such Day!");
  163.                 if ( StringWidth("\p  No Such Day!") > len )
  164.                     len = StringWidth("\p  No Such Day!");
  165.                 break;
  166.             }
  167.         
  168.         pStrCpy((char*)os,(char*)"\p  ");
  169.         NumToString(date.month,&ts);
  170.         pStrCat((char*)os,(char*)ts);
  171.         pStrCat((char*)os,(char*)"\p/");
  172.         NumToString(date.day,&ts);
  173.         pStrCat((char*)os,(char*)ts);
  174.         pStrCat((char*)os,(char*)"\p/");
  175.         NumToString(date.year,&ts);
  176.         pStrCat((char*)os,(char*)ts);
  177.         AppendMenu (mm,"\pa");
  178.         SetItem(mm,3,os);
  179.         if ( StringWidth(os) > len ) len = StringWidth(os);
  180.         
  181.         hour = date.hour;
  182.         if ( hour > 12 )
  183.             {
  184.             isAM = NO;
  185.             hour -= 12;
  186.             }
  187.         else
  188.             {
  189.             isAM = YES;
  190.             if ( hour == 0 )
  191.                 hour = 12;
  192.             }
  193.         pStrCpy((char*)os,(char*)"\p  ");            
  194.         NumToString(hour,&ts);
  195.         pRightJust((char*)ts,2);
  196.         pStrCat((char*)os,(char*)ts);
  197.         pStrCat((char*)os,(char*)"\p:");
  198.         NumToString(date.minute,&ts);
  199.         pRightJust((char*)ts,2);
  200.         pStrCat((char*)os,(char*)ts);
  201.         pStrCat((char*)os,(char*)"\p:");
  202.         NumToString(date.second,&ts);
  203.         pRightJust((char*)ts,2);
  204.         pStrCat((char*)os,(char*)ts);
  205.         if ( isAM == YES )
  206.             pStrCat((char*)os,(char*)"\p AM");
  207.         else
  208.             pStrCat((char*)os,(char*)"\p PM");
  209.             
  210.         AppendMenu (mm,"\pa");
  211.         SetItem(mm,4,os);
  212.         if ( StringWidth(os) > len ) len = StringWidth(os);
  213.         
  214.         AppendMenu (mm,"\p(-");
  215.         AppendMenu (mm,"\pWhat Day is it?");
  216.         if ( StringWidth("\pWhat Day is it?") > len ) len = StringWidth("\pWhat Day is it?");
  217.         AppendMenu (mm,"\pby Eric J. Hayes");
  218.         if ( StringWidth("\pby Eric J. Hayes") > len ) len = StringWidth("\pby Eric J. Hayes");
  219.         InsertMenu (mm,-1);
  220.         
  221.         hitPt.h = theWindow->portRect.right-len-25;
  222.         hitPt.v = 0;
  223.         LocalToGlobal(&hitPt);
  224.         Result = PopUpMenuSelect(mm,hitPt.v,hitPt.h,1);
  225.         DisposeMenu(mm);
  226.         }
  227.     }
  228.     
  229. dowindowdraw(theWindow,param)
  230.  WindowPtr    theWindow;
  231.  long        param;
  232.     {
  233.     WindowPeek    wRec;
  234.     Rect                rr;
  235.     
  236.     wRec = (WindowPeek)theWindow;
  237.     
  238.     if ( (wRec->visible == TRUE) && (wRec->hilited != FALSE) && (param == 0) )
  239.         {
  240.         rr = (*(wRec->strucRgn))->rgnBBox;
  241.         
  242.         rr.bottom = rr.top + 15;
  243.         rr.top += 4;
  244.         rr.left = rr.right - 40;
  245.         rr.right = rr.left + 11;
  246.  
  247.         InsetRect(&rr,-1,-1);
  248.         EraseRect(&rr);
  249.         InsetRect(&rr,1,1);
  250.         TextSize(9);
  251.         TextFont(monaco);
  252.         MoveTo(rr.left+3,rr.bottom-2);
  253.         DrawString("\p?");
  254.         TextSize(0);
  255.         TextFont(0);
  256.         FrameRect(&rr);
  257.         }
  258.     }
  259.